package com.buddy.learn.spring.framework.aop.aspect;

import com.buddy.learn.spring.framework.aop.intercept.BMethodInterceptor;
import com.buddy.learn.spring.framework.aop.intercept.BMethodInvocation;

import java.lang.reflect.Method;

public class BMethodBeforeAdviceInterceptor extends BAbstractAspectAdvice implements BMethodInterceptor {


    private BJoinPoint joinPoint;

    public BMethodBeforeAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void before(Method method,Object[] args,Object target) throws Throwable {

        //传送给织入的参数
//        method.invoke(target);
        super.invokeAdviceMethod(this.joinPoint,null,null);
    }

    @Override
    public Object invoke(BMethodInvocation mi) throws Throwable {
        //从被织入的代码中才能拿到，JoinPoint
        this.joinPoint = mi;
        before(mi.getMethod(),mi.getArguments(),mi.getThis());
        return mi.proceed();
    }
}
